# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libebml
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.6
pkgrel=1
pkgdesc="Extensible Binary Meta Language library (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://matroska.org"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs')
source=("https://dl.matroska.org/downloads/${_realname}/${_realname}-${pkgver}.tar.xz"
        001-mingw-use-posix-layout.patch
        002-mingw-versioned-dll.patch
        003-fix-build-with-gcc-7.patch
        004-visibility.patch)
sha256sums=('1e5a7a7820c493aa62b0f35e15b4233c792cc03458c55ebdfa7a6521e4b43e9e'
            '56273cfa7c8a653f44c743e5c33b127fc96ccaab17443313b8742926f1b9ff07'
            '0bdb0f62d4433898eef0a0d27f129150b67b60fc8d8ffe3b0e6c92eb77adb600'
            '3a9ae2683a69399effaf1406d2bd5c41c6e678a513cfe7020111c2cbc00cad60'
            '5b3537344d64199442d23ca8e5b31e34ed4f809bd676d1660322d44fdaeadff8')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-use-posix-layout.patch
  patch -p1 -i ${srcdir}/002-mingw-versioned-dll.patch
  patch -p1 -i ${srcdir}/003-fix-build-with-gcc-7.patch
  patch -p1 -i ${srcdir}/004-visibility.patch
}

build() {
  msg "Build shared library"
  [[ -d ${srcdir}/shared-${MINGW_CHOST} ]] && rm -rf ${srcdir}/shared-${MINGW_CHOST}
  mkdir -p ${srcdir}/shared-${MINGW_CHOST} && cd ${srcdir}/shared-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}/shared-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPL
}
